"use strict";

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceChoosecbinvoiceCtrl
 * @description
 * # FinanceChoosecbinvoiceCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller("FinanceChoosecbinvoiceCtrl", function(
    $scope,
    Util,
    openApi,
    localStorageService,
    PagingService
  ) {
    var relModuleObj;
    var param = {};
    // 获取搜索所需参数以及标题信息
    relModuleObj = Util.getDataforsearch();
    param = angular.extend(param, relModuleObj.param || {});
    param.callback = function(data) {
        $scope.selectLists.forEach(function(item, index) {
            data.forEach(function(subitem, index) {
                // 设置选中状态
                if (item.uid == subitem.uid) {
                    subitem.selected = true;
                }
            });
        })
    };
    // 选择后回传的数据
    $scope.selectLists = []; //已经选择了的数组，用来回传
    // -----------------底部款项类型选框添加end-----------------------
    $scope.choosePeople = function(item) {
        item.selected = !item.selected;
        if (item.selected) {
            $scope.selectLists.push(item)
        } else {
            $scope.selectLists = $scope.selectLists.filter(function(subitem, index) {
                return item.uid != subitem.uid
            })
        }
    };

    $scope.submit = function(index) {
      localStorageService.set("selectLists", $scope.selectLists);
      Util.goBack();
    };
    $scope.sellerName = param.sellerName;
    $scope.search = function(sellerName) {
      param.sellerName = sellerName;
      $scope.selectLists = Util.getSelectLists();
      $scope.taskList = new PagingService(openApi.findPaymentInvoice, param);
    };
    $scope.search();
  });
